package com.inspection.controller;

import com.inspection.entity.InspectionEventCorrectDO;
import com.inspection.entity.InspectionEventDO;
import com.inspection.model.dto.*;
import com.inspection.service.InspectionEventService;
import com.inspection.support.Wrapper;
import com.inspection.support.anno.SysLogAnno;
import com.inspection.support.model.ItemList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;


@RestController
@Slf4j
public class InspectionEventController {

    @Autowired
    private InspectionEventService inspectionEventService;

    @ApiOperation("获取考核事件列表")
    @RequestMapping("/inspect/event/page")
    public Wrapper<Page<InspectionEventDO>> pageEvent(@RequestBody InspectionEventQueryDTO page){

        return Wrapper.ok(inspectionEventService.pageEvent(page));
    }



//    @ApiOperation("获取考核事件列表")
//    @RequestMapping("/inspect/event/query")
//    public Wrapper<ItemList<InspectionEventDO>> queryEvent(@RequestBody InspectionEventQueryDTO query){
//        return Wrapper.ok(ItemList.buildItems(inspectionEventService.queryEvent(query)));
//    }

    @SysLogAnno(operateCode =110401,operateName = "考核事件：保存")
    @ApiOperation("保存考核事件")
    @RequestMapping("/inspect/event/save")
    public Wrapper<String> saveEvent(@RequestBody InspectionEventDTO save){
        inspectionEventService.saveEvent(save);
        return  Wrapper.ok("ok");
    }


    @SysLogAnno(operateCode =110402,operateName = "考核事件：修改")
    @ApiOperation("修改考核事件")
    @RequestMapping("/inspect/event/update")
    public Wrapper<String> updateEvent(@RequestBody InspectionEventDTO update){
        inspectionEventService.updateEvent(update);
        return  Wrapper.ok("ok");
    }
    @ApiOperation("獲取考核事件")
    @RequestMapping("/inspect/event/get")
    public Wrapper<InspectionEventDO> getEvent(@RequestBody InspectionEventDTO query){
        return Wrapper.ok(inspectionEventService.getEvent(query)) ;
    }

    @SysLogAnno(operateCode =110403,operateName = "考核事件：删除")
    @ApiOperation("删除考核事件")
    @RequestMapping("/inspect/event/del")
    public Wrapper<String> delEvent(@RequestBody InspectionEventDTO del) {
        inspectionEventService.delEvent(del);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =110404,operateName = "考核事件：批量删除")
    @ApiOperation("删除考核事件")
    @RequestMapping("/inspect/event/batchDel")
    public Wrapper<String> batchDelEvent(@RequestBody InspectionEventDTO del) {
        inspectionEventService.batchDelEvent(del);
        return Wrapper.ok("ok");
    }



    @ApiOperation("获取事件的整改详情,可能为空")
    @RequestMapping("/inspect/event/correct/get")
    public Wrapper<InspectionEventCorrectDO> getEventCorrect(@RequestBody InspectionEventCorrectQueryDTO query) {
        return Wrapper.ok(inspectionEventService.getEventCorrect(query));
    }


    @SysLogAnno(operateCode =110405,operateName = "考核事件：整改")
    @ApiOperation("整改 如果已经存在整改详情，覆盖更新")
    @RequestMapping("/inspect/event/correct")
    public Wrapper<String> correctEvent(@RequestBody InspectionEventCorrectDTO correct) {
        inspectionEventService.correctEvent(correct);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =110406,operateName = "考核事件：审核")
    @ApiOperation("审核")
    @RequestMapping("/inspect/event/approve")
    public Wrapper<String> approveEvent(@RequestBody InspectionEventDTO approve) {
        inspectionEventService.approveEvent(approve);
        return Wrapper.ok("ok");
    }


    @RequestMapping("/inspect/event/export")
    public void exportUser(HttpServletResponse response) {
        inspectionEventService.exportEvent(new InspectionEventQueryDTO(), response);
    }



}
